www.gusucode.com > VC 2D游戏编辑器-源码程序 > VC 2D游戏编辑器-源码程序/code/mapedit_source/map/NewMap.cpp

    //Download by http://www.NewXing.com
// NewMap.cpp : implementation file
//

#include "stdafx.h"
#include "..\\MapEdit.h"
#include "NewMap.h"
#include "Map.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern _SurfaceCell cSelSurface;
_SurfaceCell cOldSurface;
extern CString* cSourPath;
extern int nSource;

/////////////////////////////////////////////////////////////////////////////
// CNewMap dialog


CNewMap::CNewMap(CWnd* pParent /*=NULL*/)
	: CDialog(CNewMap::IDD, pParent)
{
	//{{AFX_DATA_INIT(CNewMap)
	m_issquare = FALSE;
	m_nWidth = 0;
	m_nHeight = 0;
	m_height = 0;
	m_id = 0;
	m_pass = FALSE;
	m_type = 0;
	m_mapid = 0;
	//}}AFX_DATA_INIT
	m_imageList=new CImageList;
}


void CNewMap::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNewMap)
	DDX_Control(pDX, IDC_MAP_WIDTH, m_map_width);
	DDX_Control(pDX, IDC_MAP_HEIGHT, m_map_height);
	DDX_Control(pDX, IDC_FLOORLIST, m_floorlist);
	DDX_Check(pDX, IDC_ISSQUARE, m_issquare);
	DDX_Text(pDX, IDC_MAP_WIDTH, m_nWidth);
	DDX_Text(pDX, IDC_MAP_HEIGHT, m_nHeight);
	DDX_Text(pDX, IDC_HEIGHT2, m_height);
	DDV_MinMaxInt(pDX, m_height, 0, 31);
	DDX_Text(pDX, IDC_ID, m_id);
	DDV_MinMaxInt(pDX, m_id, 0, 127);
	DDX_Check(pDX, IDC_PASS, m_pass);
	DDX_Text(pDX, IDC_TYPE, m_type);
	DDV_MinMaxInt(pDX, m_type, 0, 7);
	DDX_Text(pDX, IDC_MAPID, m_mapid);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CNewMap, CDialog)
	//{{AFX_MSG_MAP(CNewMap)
	ON_BN_CLICKED(IDC_ISSQUARE, OnIssquare)
	ON_NOTIFY(LVN_ITEMCHANGED, IDC_FLOORLIST, OnItemchangedFloorlist)
	ON_WM_DESTROY()
	ON_WM_SHOWWINDOW()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNewMap message handlers

void CNewMap::OnIssquare() 
{
	// TODO: Add your control notification handler code here
	if(GetDlgItem(IDC_MAP_HEIGHT)->IsWindowEnabled())
	{
		GetDlgItem(IDC_MAP_HEIGHT)->EnableWindow(FALSE);
		GetDlgItem(IDC_HEIGHT)->EnableWindow(FALSE);
	}
	else
	{
		GetDlgItem(IDC_MAP_HEIGHT)->EnableWindow(TRUE);
		GetDlgItem(IDC_HEIGHT)->EnableWindow(TRUE);
	}
}

BOOL CNewMap::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CSize sz(70,60);
	m_floorlist.SetIconSpacing(sz);
	m_floorlist.SetBkColor(RGB(255,255,255));
	m_imageList->Create(32, 32, ILC_COLOR24 , 0, 128);
	m_floorlist.SetImageList(m_imageList,LVSIL_NORMAL);
	int i;
	for (i=0;i<nSource;i++)
		LoadListItem(i, cSourPath[i]);
	if ( m_strCaption.GetLength() )
        SetWindowText( m_strCaption );

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CNewMap::LoadListItem(int nItem, CString str)
{
	CBitmap *bmp;
	HBITMAP hp;
	int i=0,j=0;
	char filename[32];
	char result[MAX_PATH];
	GetCurrentDirectory(MAX_PATH,result);
	strcat(result,"\\resource\\");
	strcat(result,str);
	hp=(HBITMAP)LoadImage( NULL, result, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE );
	bmp=CBitmap::FromHandle(hp);
	m_imageList->Add(bmp, RGB(0, 0, 0));

	i = str.Find('\\', 0);
	i ++;
	while(str[i] != '.')
		filename[j++] = str[i++];
	filename[j] = '\0';
	m_floorlist.InsertItem(nItem,filename,m_imageList->GetImageCount()-1);
}

void CNewMap::OnItemchangedFloorlist(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	CListCtrl *pList = (CListCtrl *)GetDlgItem(IDC_FLOORLIST);
	int nSelected = pNMListView->iItem;
	if(nSelected >= 0)
	{
		cSelSurface.nID = nSelected;
		cSelSurface.nHeight = 0;
		cSelSurface.nPass = 1;
		cSelSurface.nEvent = 0;
		cSelSurface.nEventType = 0;
		cSelSurface.res = 0;
	}
	*pResult = 0;
}


void CNewMap::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	if(m_imageList)
		delete m_imageList;
}


void CNewMap::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CDialog::OnShowWindow(bShow, nStatus);
	
	// TODO: Add your message handler code here
	m_map_width.SetCurSel(0);
	m_map_height.SetCurSel(0);
	cOldSurface.nID = cSelSurface.nID;
	cOldSurface.nHeight = cSelSurface.nHeight;
	cOldSurface.nPass = cSelSurface.nPass;
	cOldSurface.nEvent = cSelSurface.nEvent;
	cOldSurface.nEventType = cSelSurface.nEventType;
	cOldSurface.res = cSelSurface.res;

	cSelSurface.nID = 0;
	cSelSurface.nHeight = 0;
	cSelSurface.nPass = 1;
	cSelSurface.nEvent = 0;
	cSelSurface.nEventType = 0;
	cSelSurface.res = 0;
}